package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.common.exception.CustomException;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", tags = "channel", description = "频道管理API")
@ApiOperation("频道管理")
public class AdChannelController {
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @ApiOperation("频道名称模糊分页查询")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        System.out.println("111111");
        return adChannelService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @ApiOperation("增加频道")
    public ResponseResult insert(@RequestBody AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }

    @PostMapping("/update")
    @ApiOperation("修改频道")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation("删除频道")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        if (true) {
            throw new CustomException(AppHttpCodeEnum.DATA_EXIST);
        }
        return adChannelService.delete(id);
    }
@GetMapping("/channels")
    public ResponseResult findAll(){
    List<AdChannel> list = adChannelService.list();
    return ResponseResult.okResult(list);
}
}